<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #drag{
            width: 150px;
            height:150px;
            background-color: red;
            position: absolute;
            left:0;
            top:0;
        }
        #dist{
            width: 500px;
            height: 500px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div id="drag" draggable="true"></div>
    <div id="dist" ></div>
    <script>
        let drag = document.getElementById("drag");
        let dist = document.getElementById("dist");
        let x = 0;
        let y = 0;
        drag.ondragstart = function(e){
            x = e.x - parseInt(this.style.left || 0);
            y = e.y - parseInt(this.style.top || 0);
        }
        // drag.ondrag = function(){
        //     console.log("drag");
        // }
        drag.ondragend = function(e){
            this.style.left = e.x - x + "px";
            this.style.top = e.y - y + "px";
        }
        // document.body.ondragenter = function(){
        //     console.log("dragenter");
        // }
        // document.body.ondragover = function(){
        //     console.log("dragover");
        // }
        // document.body.ondragleave = function(){
        //     console.log("dragleave");
        // }
        document.body.ondrop = function(e){
            // e.preventDefault();
            console.log("drop");
        }
        document.body.ondragover = function(e){
            // e.preventDefault();
        }
        // dist.ondragover = function(e){
        //     e.preventDefault();
        //     // console.log("drop");
        // }
        // dist.ondrop = function(){
        //     console.log("drop");
        // }
    </script>
</body>
</html>